package com.nbsaas.boot.shopping.rest.convert;

import com.nbsaas.boot.shopping.data.entity.ShoppingCart;
import com.nbsaas.boot.shopping.api.domain.simple.ShoppingCartSimple;

import com.nbsaas.boot.rest.api.Converter;

/**
* 购物车-列表对象转换器
*/

public class ShoppingCartSimpleConvert implements Converter<ShoppingCartSimple, ShoppingCart> {




@Override
public ShoppingCartSimple convert(ShoppingCart source) {
    ShoppingCartSimple result = new ShoppingCartSimple();


               try {
                   if(source.getProduct()!=null){
                       result.setProduct(source.getProduct().getId());
                   }
                } catch (Exception ignored) { }


               try {
                   if(source.getCreator()!=null){
                       result.setCreator(source.getCreator().getId());
                   }
                } catch (Exception ignored) { }


               try {
                   if(source.getShop()!=null){
                       result.setShop(source.getShop().getId());
                   }
                } catch (Exception ignored) { }

                result.setTotalPrice(source.getTotalPrice());
                result.setNum(source.getNum());

                try {
                    if(source.getShop()!=null){
                        result.setShopName(source.getShop().getName());
                    }
                } catch (Exception ignored) { }

                if(source.getProduct()!=null){
                    result.setProductLogo(source.getProduct().getLogo());
                }
                result.setAddDate(source.getAddDate());
                if(source.getProduct()!=null){
                    result.setProductState(source.getProduct().getState());
                }

                try {
                    if(source.getProduct()!=null){
                        result.setProductName(source.getProduct().getName());
                    }
                } catch (Exception ignored) { }


                try {
                    if(source.getSku()!=null){
                        result.setSkuName(source.getSku().getName());
                    }
                } catch (Exception ignored) { }

                result.setPrice(source.getPrice());
                result.setChecked(source.getChecked());
                result.setId(source.getId());

               try {
                   if(source.getSku()!=null){
                       result.setSku(source.getSku().getId());
                   }
                } catch (Exception ignored) { }

                result.setLastDate(source.getLastDate());


    return result;
}

}